package com.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import com.dto.AdminLoginDto;
import com.dto.AdminSaveDto;
import com.po.User;
import com.result.Result;
import com.service.AdminService;
import com.service.UserService;
import com.vo.AdminLoginVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**管理员
 * @param
 * @return
 */
@RequestMapping("/admin")
//@SaCheckRole("admin")
@RequiredArgsConstructor
@RestController
@Slf4j
public class AdminController {

    private final AdminService adminService;


    /**
     * 管理员注册
     * @param adminSaveDto
     * @return
     */
    @SaCheckPermission("user::master")
    @PostMapping("/register")
    public Result register(@RequestBody AdminSaveDto adminSaveDto){
        adminService.registerForAdmin(adminSaveDto);
        return Result.success();
    }

    /**
     * 权限测试
     * @return
     */
    @RequestMapping("/test")
    public Result test(){
        StpUtil.checkPermissionOr("user::master","user::admin");
        return Result.success("有权力");
    }
    /**
     * 修改用户状态
     */
    @SaCheckPermission("user::master")
    @PutMapping("/setUserStatus")
    public Result setUserStatus(@RequestParam Long userId){
        adminService.setUserStatus(userId);
        return Result.success();
    }
}
